package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.ChargingPileDao;
import cn.topevery.garden.entity.po.ChargingPile;
import cn.topevery.garden.entity.query.ChargingPileQuery;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author code-generate
 * @date 2021-08-06
 */
@Repository
public class ChargingPileDaoImpl extends BaseDaoImpl<ChargingPile> implements ChargingPileDao {
    @Override
    public <P extends DbCsp> List<ChargingPile> getSearch(P para) {
        return null;
    }


    @Override
    public DataPager<ChargingPile> listPage(ChargingPileQuery query) {
        String table = "t_charging_pile tcp";

        String columns = "tcp.*";
        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tcp.c_id desc");
        sqlQueryMate
                .where(true, "tcp.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(StringUtils.isNotBlank(query.getCode()), "tcp.c_code", ScriptConditionEnum.Like, query.getCode())
                .where(StringUtils.isNotBlank(query.getParkName()), "tcp.c_park_name", ScriptConditionEnum.Like, query.getParkName())
                .where(query.getStatus() != null, "tcp.c_status", ScriptConditionEnum.Eq, query.getStatus())
                .where(query.getParkId() != null, "tcp.c_park_id", ScriptConditionEnum.Eq, query.getParkId());

        return getDataPager(sqlQueryMate, pageSize, pageIndex, ChargingPile.class);
    }


}
